package com.openbravo.data.gui;

import com.openbravo.basic.BasicException;
import com.openbravo.data.loader.ComparatorCreator;
import com.openbravo.data.loader.LocalRes;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Comparator;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRootPane;

public class JSort extends JDialog
{
  private ComparatorCreator m_cc;
  private Comparator m_Comparator;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JLabel jLabel4;
  private JPanel jPanel1;
  private JPanel jPanel2;
  private JButton jcmdCancel;
  private JButton jcmdOK;
  private JComboBox m_jSort1;
  private JComboBox m_jSort2;
  private JComboBox m_jSort3;

  private JSort(Frame paramFrame, boolean paramBoolean)
  {
    super(paramFrame, paramBoolean);
  }

  private JSort(Dialog paramDialog, boolean paramBoolean)
  {
    super(paramDialog, paramBoolean);
  }

  private Comparator init(ComparatorCreator paramComparatorCreator)
    throws BasicException
  {
    initComponents();
    getRootPane().setDefaultButton(this.jcmdOK);
    this.m_cc = paramComparatorCreator;
    String[] arrayOfString = this.m_cc.getHeaders();
    this.m_jSort1.removeAllItems();
    this.m_jSort1.addItem("");
    for (int i = 0; i < arrayOfString.length; i++)
      this.m_jSort1.addItem(arrayOfString[i]);
    this.m_jSort1.setSelectedItem(Integer.valueOf(0));
    this.m_jSort2.removeAllItems();
    this.m_jSort2.addItem("");
    for (int i = 0; i < arrayOfString.length; i++)
      this.m_jSort2.addItem(arrayOfString[i]);
    this.m_jSort2.setSelectedItem(Integer.valueOf(0));
    this.m_jSort3.removeAllItems();
    this.m_jSort3.addItem("");
    for (int i = 0; i < arrayOfString.length; i++)
      this.m_jSort3.addItem(arrayOfString[i]);
    this.m_jSort3.setSelectedItem(Integer.valueOf(0));
    this.m_Comparator = null;
    setVisible(true);
    return this.m_Comparator;
  }

  private static Window getWindow(Component paramComponent)
  {
    if (paramComponent == null)
      return new JFrame();
    if (((paramComponent instanceof Frame)) || ((paramComponent instanceof Dialog)))
      return (Window)paramComponent;
    return getWindow(paramComponent.getParent());
  }

  public static Comparator showMessage(Component paramComponent, ComparatorCreator paramComparatorCreator)
    throws BasicException
  {
    Window localWindow = getWindow(paramComponent);
    JSort localJSort;
    if ((localWindow instanceof Frame))
      localJSort = new JSort((Frame)localWindow, true);
    else
      localJSort = new JSort((Dialog)localWindow, true);
    return localJSort.init(paramComparatorCreator);
  }

  private void initComponents()
  {
    this.jPanel1 = new JPanel();
    this.jLabel2 = new JLabel();
    this.m_jSort1 = new JComboBox();
    this.jLabel3 = new JLabel();
    this.m_jSort2 = new JComboBox();
    this.jLabel4 = new JLabel();
    this.m_jSort3 = new JComboBox();
    this.jPanel2 = new JPanel();
    this.jcmdOK = new JButton();
    this.jcmdCancel = new JButton();
    setDefaultCloseOperation(2);
    setTitle(LocalRes.getIntString("caption.sort"));
    setResizable(false);
    this.jPanel1.setLayout(null);
    this.jLabel2.setText(LocalRes.getIntString("label.sortby"));
    this.jPanel1.add(this.jLabel2);
    this.jLabel2.setBounds(10, 20, 100, 14);
    this.jPanel1.add(this.m_jSort1);
    this.m_jSort1.setBounds(110, 20, 230, 22);
    this.jLabel3.setText(LocalRes.getIntString("label.andby"));
    this.jPanel1.add(this.jLabel3);
    this.jLabel3.setBounds(10, 50, 100, 14);
    this.jPanel1.add(this.m_jSort2);
    this.m_jSort2.setBounds(110, 50, 230, 22);
    this.jLabel4.setText(LocalRes.getIntString("label.andby"));
    this.jPanel1.add(this.jLabel4);
    this.jLabel4.setBounds(10, 80, 100, 14);
    this.jPanel1.add(this.m_jSort3);
    this.m_jSort3.setBounds(110, 80, 230, 22);
    getContentPane().add(this.jPanel1, "Center");
    this.jPanel2.setLayout(new FlowLayout(2));
    this.jcmdOK.setText(LocalRes.getIntString("button.ok"));
    this.jcmdOK.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JSort.this.jcmdOKActionPerformed(paramActionEvent);
      }
    });
    this.jPanel2.add(this.jcmdOK);
    this.jcmdCancel.setText(LocalRes.getIntString("button.cancel"));
    this.jcmdCancel.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JSort.this.jcmdCancelActionPerformed(paramActionEvent);
      }
    });
    this.jPanel2.add(this.jcmdCancel);
    getContentPane().add(this.jPanel2, "South");
    Dimension localDimension = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((localDimension.width - 396) / 2, (localDimension.height - 199) / 2, 396, 199);
  }

  private void jcmdCancelActionPerformed(ActionEvent paramActionEvent)
  {
    dispose();
  }

  private void jcmdOKActionPerformed(ActionEvent paramActionEvent)
  {
    int i = this.m_jSort1.getSelectedIndex();
    int j = this.m_jSort2.getSelectedIndex();
    int k = this.m_jSort3.getSelectedIndex();
    if ((i > 0) && (j == 0) && (k == 0))
    {
      this.m_Comparator = this.m_cc.createComparator(new int[] { i - 1 });
      dispose();
    }
    else if ((i > 0) && (j > 0) && (k == 0))
    {
      this.m_Comparator = this.m_cc.createComparator(new int[] { i - 1, j - 1 });
      dispose();
    }
    else if ((i > 0) && (j > 0) && (k > 0))
    {
      this.m_Comparator = this.m_cc.createComparator(new int[] { i - 1, j - 1, k - 1 });
      dispose();
    }
    else
    {
      MessageInf localMessageInf = new MessageInf(-67108864, LocalRes.getIntString("message.nosort"));
      localMessageInf.show(this);
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.data.gui.JSort
 * JD-Core Version:    0.6.0
 */